package cn.lb.permission.controller;

import cn.lb.permission.domain.Menu;
import cn.lb.permission.service.IMenuService;
import cn.lb.basic.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private IMenuService service;

   @GetMapping("/tree")
    public R tree(){
       try {
           List<Menu> menuList=service.tree();
           return R.me().setData(menuList);
       } catch (Exception e) {
           e.printStackTrace();
           return R.me().setSuccess(false).setMessage("失败"+e.getMessage());
       }
   }

    @GetMapping("/treetree")
    public R trees( Long userId){
        try {
            List<Menu> menuList=service.list(userId);
            System.out.println(menuList);
            return R.me().setData(menuList);
        } catch (Exception e) {
            e.printStackTrace();
            return R.me().setSuccess(false).setMessage("失败"+e.getMessage());
        }
    }
}
